package com.kun.lagou.user.service;

import com.kun.lagou.user.dao.UserDao;
import com.kun.lagou.user.model.User;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author Administrator
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class UserService {
    private final UserDao userDao;

    public User getUser(long userId) {
        return userDao.findById(userId).get();
    }

    public User login(String phoneNumber, String code) {
        //TODO 校验验证码
        return userDao.findByPhoneNumber(phoneNumber)
                .orElseGet(() -> userDao.save(User.builder()
                        .nickname(phoneNumber)
                        .phoneNumber(phoneNumber).build()));
    }









}
